const app = getApp()
const API = require("../../http/api")
// pages/sou/sou.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
       query:'',
       his:wx.getStorageSync('his')||[]
    },
   async search(e){
        // console.log(e)
       this.setData({
           query:e.detail.value
       })
       wx.navigateTo({
         url: '/pages/soulist/soulist?query='+this.data.query,
       })

       if(this.data.query.length==0){
           return false
       }
       const data=new Date()
       const time=data.getTime()
       console.log(time)
       const index=this.data.his.findIndex(item=>{
           return item.txt==this.data.query
       })
       if(index>-1){
           return false
       }
       let obj={
        id:time,
        txt:this.data.query
    }
       this.data.his.push(obj)
       this.setData({
           his:this.data.his
       })
       wx.setStorageSync('his', this.data.his)
   
    },
    gosou(e){
        console.log(e)
        const zi=e.target.dataset.txt
        wx.navigateTo({
            url: '/pages/soulist/soulist?query='+zi,
        })
    },
    del(e){
      console.log(e)
      const index=e.target.dataset.index
      this.data.his.splice(index,1)
      this.setData({
          his:this.data.his
      })
      wx.setStorageSync('his',this.data.his)
    },
})